<!DOCTYPE html>
<html th:lang="${language}"  xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header(#{okr.synergy})" />
    <th:block th:include="include :: okr-css" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse collapse">
            <form id="okr_synergy_form">
                <div class="select-list">
                    <ul class="row">
                        <li class="col-xs-12 col-sm-6 col-md-4">
                            <label>排序编号：</label>
                            <input type="text" name="sortId"/>
                        </li>
                        <li class="col-xs-12 col-sm-6 col-md-4">
                            <label>编号：</label>
                            <input type="text" name="rowCode"/>
                        </li>
                        <li class="col-xs-12 col-sm-6 col-md-4">
                            <label>内容描述：</label>
                            <input type="text" name="content"/>
                        </li>
                        <li class="col-xs-12 col-sm-6 col-md-4">
                            <label>类型：</label>
                            <select name="rowType" th:with="type=${@dict.getType('okr_row_type')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li class="col-xs-12 col-sm-6 col-md-4">
                            <label>信心指数：</label>
                            <input type="text" name="confidenceStar"/>
                        </li>
                        <li class="col-xs-12 col-sm-6 col-md-4">
                            <label>用户标识：</label>
                            <input type="text" name="userId"/>
                        </li>
                        <li class="col-xs-12 col-sm-6 col-md-4">
                            <label>目标评分：</label>
                            <input type="text" name="scoreStar"/>
                        </li>
                        <li class="col-xs-12 col-sm-6 col-md-4">
                            <label>父级ID：</label>
                            <input type="text" name="parentId"/>
                        </li>
                        <li class="col-xs-12 col-sm-6 col-md-4">
                            <label>周期ID：</label>
                            <input type="hidden" name="cycleId"  id="cycleId"/>
                        </li>
                        <li class="col-xs-12 col-sm-6 col-md-4">
                            <label>目标进度：</label>
                            <input type="text" name="process"/>
                        </li>
                        <li class="col-xs-12 col-sm-6 col-md-4">
                            <label>状态：</label>
                            <select name="status" th:with="type=${@dict.getType('row_status')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li class="col-xs-12 col-sm-6 col-md-4">
                            <label>优先级：</label>
                            <input type="text" name="priority"/>
                        </li>
                        <li class="col-xs-12 col-sm-6 col-md-4">
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-info" id="expandAllBtn">
                <i class="fa fa-exchange"></i> [[#{okr.openORclose}]]
            </a>
            <div class="btn-group">
                <select class="form-control" data-style="btn-success"  id="cycleIdSelect"  th:onchange="changeCycleType()">
                    <optgroup th:label="#{okr.yearChoice}">
                        <div th:each="cycle : ${cycleList}">
                            <div th:if="${cycle.cycleType == 1}">
                                <span th:if="${cycle.status == 0}">
                                        <option th:value="${cycle.id}" selected="selected" th:text="${cycle.cycleName}"></option>
                                </span>
                                <span th:if="${cycle.status == 1}">
                                        <option th:value="${cycle.id}" th:text="${cycle.cycleName}"></option>
                                </span>
                            </div>
                        </div>
                    </optgroup>
                    <optgroup th:label="#{okr.quarterChoice}">
                        <div th:each="cycle : ${cycleList}">
                            <div th:if="${cycle.cycleType == 0}">
                                <span th:if="${cycle.status == 0}">
                                        <option th:value="${cycle.id}" selected="selected" th:text="${cycle.cycleName}"></option>
                                </span>
                                <span th:if="${cycle.status == 1}">
                                        <option th:value="${cycle.id}" th:text="${cycle.cycleName}"></option>
                                </span>
                            </div>
                        </div>
                    </optgroup>
                </select>
            </div>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-tree-table" ></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var cycleFlag = [[${@permission.hasPermi('okr:cycle:useList')}]];
    var rowTypeDatas = [[${@dict.getType('okr_row_type')}]];  
    var removeFlag = [[${@permission.hasPermi('okr:info:remove')}]];
    var scoreStarDatas = [[${@dict.getType('ork_fraction')}]];
    var statusDatas = [[${@dict.getType('row_status')}]];
    var priorityDatas = [[${@dict.getType('okr_level')}]];
    var prefix = ctx + "okr/synergy";
    $(function() {
        var options = {
            code: "rowId",
            parentCode: "parentId",
            uniqueId: "id",
            expandAll: true,
            expandFirst: false,
            url: prefix + "/list",
            search:true,
            modalName: [[#{okr.synergyInfo}]],
            striped:true,
            columns: [
                {
                    field: 'selectItem',
                    radio: true
                },
                {
                    field: 'rowCode',
                    title: [[#{okr.id}]],
                    formatter: function(value, row, index) {
                        if( row.rowType == 0 ){
                            return '<span>O'+value+'</span>';
                        } else {
                            return '<span>KR'+value+'</span>';
                        }
                    }
                },
                {
                    field: 'content',
                    title: [[#{okr.content}]],
                    classes:'col-xs-12 col-md-5',
                },
                {
                    field: 'loginName',
                    title: [[#{okr.synergyUserName}]],
                },
                {
                    field: 'deptName',
                    title: [[#{okr.synergyUserDept}]],
                },
                {
                    field: 'priority',
                    title: [[#{okr.priority}]],
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(priorityDatas, value);
                    }
                },
                {
                    field: 'operation',
                    title: [[#{okr.operation}]],
                    align: 'right',
                    classes:'col-xs-12 operation-long',
                    formatter: function(value, row, index) {
                        let actions  = [];
                        if (row.rowType==0) { //判断是否是关键结果
                            actions.push('<a class="btn btn-primary btn-xs ' + rowTypeDatas + '" href="javascript:void(0)" onclick=viewDetailOkr('+ row.id + ',"'+ row.userName +'")><i class="fa fa-edit"></i>[(#{okr.viewDetails})]</a>');
                            if(row.align==true) { //判断是否已经添加对齐
                                actions.push('<a class="btn btn-primary btn-xs ' + rowTypeDatas + '" href="javascript:void(0)" onclick=selectOkr('+ row.id + ')><i class="fa fa-edit"></i>[(#{okr.viewAlignment})]</a>');
                            } else {
                                actions.push('<a class="btn btn-success btn-xs ' + rowTypeDatas + '" href="javascript:void(0)" onclick=selectOkr('+ row.id + ')><i class="fa fa-edit"></i>[(#{okr.addAlignment})]</a>');
                            }
                        }
                        return actions.join('');
                    }
                }
            ]
        };
        $.treeTable.init(options);
    });

    //产看okr 详情页面
    function viewDetailOkr(okrId,userName) {
        $.modal.openTab( "&lceil;&nbsp;"+ userName +"&nbsp;&rfloor;的okr详情页" , ctx + "okr/info/managerView/" + okrId);
    }

    /* 分配OKR */
    function selectOkr(okrId) {
        $.modal.open([[#{okr.addAlignMy}]], ctx + "okr/info/selectOkr/" + okrId);
    }

    //OKR 周期切换
    function changeCycleType(type) {
        $("#cycleId").val($("#cycleIdSelect").val());
        $.treeTable.search();
    }
</script>
</body>
</html>